﻿using UnityEngine;
using System.Collections;

public class ResourceTester : MonoBehaviour {

	// Use this for initialization
	void GetResourceList () {
        Object[] sortedAll = Resources.FindObjectsOfTypeAll(typeof(Texture2D));
        int max = sortedAll.Length;
        for (int i = 0; i < max - 1; i++)
        {
            for (int j = 0; j < max - 1; j++)
            {
                if (Profiler.GetRuntimeMemorySize(sortedAll[j]) < Profiler.GetRuntimeMemorySize(sortedAll[j + 1]))
                {
                    Object t = sortedAll[j];
                    sortedAll[j] = sortedAll[j + 1];
                    sortedAll[j + 1] = t;
                }
            }
        }

        int total = 0;
        int temp = 0;
        for (int i = 0; i < max; i++)
        {
            temp = Profiler.GetRuntimeMemorySize(sortedAll[i]);

            Debug.Log(sortedAll[i].name + " = " + (temp / (1024.0f * 1024.0f)) + "MB");
            total += temp;      
        }

        Debug.Log("total = " + (total / (1024.0f * 1024.0f)) + "MB");
	}
	
	// Update is called once per frame
	void Update () {
	
        if(Input.GetKeyDown(KeyCode.Space))
        {
            GetResourceList();
        }
	}
}
